Imports NUnit.Framework

<TestFixture()> _
Public Class nunit_test_IBANAnalyzer

    <TestFixtureSetUp()> _
    Public Sub Init()
        IBANDefinitions.ReadDefinitions("..\..\IBANFuncsCore\IBANDefinitions.xml")
    End Sub

    <TestFixtureTearDown()> _
    Public Sub Cleanup()
    End Sub

    <Test()> _
    Public Sub TestAustriaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("AT"))
    End Sub

    <Test()> _
    Public Sub TestAndorraIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("AD"))
    End Sub

    <Test()> _
    Public Sub TestBelgiumIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("BE"))
    End Sub

    <Test()> _
    Public Sub TestCroatiaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("HR"))
    End Sub

    <Test()> _
    Public Sub TestCyprusIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("CY"))
    End Sub

    <Test()> _
    Public Sub TestCzechRepublicIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("CZ"))
    End Sub

    <Test()> _
    Public Sub TestDenmarkIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("DK"))
    End Sub

    <Test()> _
    Public Sub TestEstoniaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("EE"))
    End Sub

    <Test()> _
    Public Sub TestFinlandIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("FI"))
    End Sub

    <Test()> _
    Public Sub TestFranceIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("FR"))
    End Sub

    <Test()> _
    Public Sub TestGermanyIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("DE"))
    End Sub

    <Test()> _
    Public Sub TestGibraltarIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("GI"))
    End Sub

    <Test()> _
    Public Sub TestGreeceIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("GR"))
    End Sub

    <Test()> _
    Public Sub TestHungaryIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("HU"))
    End Sub

    <Test()> _
    Public Sub TestIcelandIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("IS"))
    End Sub

    <Test()> _
    Public Sub TestIrelandIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("IE"))
    End Sub

    <Test()> _
    Public Sub TestItalyIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("IT"))
    End Sub

    <Test()> _
    Public Sub TestLatviaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("LV"))
    End Sub

    <Test()> _
    Public Sub TestLiechtensteinIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("LI"))
    End Sub

    <Test()> _
    Public Sub TestLithuaniaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("LT"))
    End Sub

    <Test()> _
    Public Sub TestLuxembourgIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("LU"))
    End Sub

    <Test()> _
    Public Sub TestMaltaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("MT"))
    End Sub

    <Test()> _
    Public Sub TestNetherlandIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("NL"))
    End Sub

    <Test()> _
    Public Sub TestNorwayIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("NO"))
    End Sub

    <Test()> _
    Public Sub TestPolandIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("PL"))
    End Sub

    <Test()> _
    Public Sub TestPortugalIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("PT"))
    End Sub

    <Test()> _
    Public Sub TestRomaniaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("RO"))
    End Sub

    <Test()> _
    Public Sub TestSlovakRepublicIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("SK"))
    End Sub

    <Test()> _
    Public Sub TestSloveniaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("SI"))
    End Sub

    <Test()> _
    Public Sub TestSpainIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("ES"))
    End Sub

    <Test()> _
    Public Sub TestSwedenIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("SE"))
    End Sub

    <Test()> _
    Public Sub TestSwitzerlandIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("CH"))
    End Sub

    <Test()> _
    Public Sub TestTunisiaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("TN"))
    End Sub

    <Test()> _
    Public Sub TestUnitedKingdomIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("GB"))
    End Sub

    <Test()> _
    Public Sub TestBosniaHergezegovinaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("BA"))
    End Sub

    <Test()> _
    Public Sub TestBulgariaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("BG"))
    End Sub

    <Test()> _
    Public Sub TestMacedoniaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("MK"))
    End Sub

    <Test()> _
    Public Sub TestMontenegroIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("ME"))
    End Sub

    <Test()> _
    Public Sub TestSerbiaIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("RS"))
    End Sub

    <Test()> _
    Public Sub TestTurkeyIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("TR"))
    End Sub

    <Test()> _
    Public Sub TestMauritiusIBANAnalysis()
        TestIBANAnalysis(nunit.nunit_const.FindElementIndex("MU"))
    End Sub

    <Test()> _
    Public Sub Test_NotNumericException()
        Try
            Dim IBAN As IBANContents = IBANAnalyzer.AnalyzeIBAN("GR16A1101250000000012300695")
            Assert.Fail("No exception (expected XIBANNotNumericException)")
        Catch ex As XIBANNotNumericException
        Catch ex As Exception
            Assert.Fail("Invalid exception (expected XIBANNotNumericException), " + ex.ToString())
        End Try
    End Sub

    <Test()> _
    Public Sub Test_InvalidCheckDigitsException()
        Try
            Dim IBAN As IBANContents = IBANAnalyzer.AnalyzeIBAN("GR9601101250000000012300695")
            Assert.Fail("No exception (expected XIBANIncorrectCheckDigitsException)")
        Catch ex As XIBANIncorrectCheckDigitsException
        Catch ex As Exception
            Assert.Fail("Invalid exception (expected XIBANIncorrectCheckDigitsException), " + ex.ToString())
        End Try
    End Sub

    <Test()> _
    Public Sub Test_NumericCharacterException()
        Try
            Dim IBAN As IBANContents = IBANAnalyzer.AnalyzeIBAN("FR9620041010050500013002606")
            Assert.Fail("No exception (expected XIBANNumericCharacterException)")
        Catch ex As XIBANNumericCharacterException
        Catch ex As Exception
            Assert.Fail("Invalid exception (expected XIBANNumericCharacterException), " + ex.ToString())
        End Try
    End Sub

    <Test()> _
    Public Sub Test_InvalidCountryException()
        Try
            Dim IBAN As IBANContents = IBANAnalyzer.AnalyzeIBAN("ZZ1601101250000000012300695")
            Assert.Fail("No exception (expected XIBANInvalidCountryCodeException)")
        Catch ex As XIBANInvalidCountryCodeException
        Catch ex As Exception
            Assert.Fail("Invalid exception (expected XIBANInvalidCountryCodeException), " + ex.ToString())
        End Try
    End Sub

    Private Sub TestIBANAlalysis(ByVal testRecord As IBANTestRecord)
        Try
            Dim IBAN As IBANContents = IBANAnalyzer.AnalyzeIBAN(testRecord.IBANString)
            Console.WriteLine("IBAN Analysis results")
            Console.WriteLine("=====================")
            Console.WriteLine("Country: " + IBAN.CountryCode)
            Console.WriteLine("Check digits: " + IBAN.CheckDigits)
            Console.WriteLine("Bank code: " + IBAN.BankCode)
            Console.WriteLine("Branch code: " + IBAN.BranchCode)
            Console.WriteLine("Account number: " + IBAN.AccountNumber)
            Assert.IsTrue(testRecord.Equals(IBAN))
        Catch ex As Exception
            Console.WriteLine("Exception on TestIBANAnalysis (" + ex.ToString() + ")")
            Assert.Fail("Exception on TestIBANAnalysis (" + ex.ToString() + ")")
        End Try
    End Sub

    Private Sub TestIBANAnalysis(ByVal index As Integer)
        TestIBANAlalysis(nunit_const.IBANRecords(index))
    End Sub

End Class
